<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<!-- modify by zhangwei -->
<!-- 百度站长 -->
<meta name="baidu-site-verification" content="MdPKZBgY0U">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



  <meta name="google-site-verification" content="8DKRuNxJDPU2k6cNyVhLe_eSqGk-R8oiYk8iKMg5gwI">














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/uploads/favicon.ico?v=5.1.4" color="#222">





  <meta name="keywords" content="Android-Adapter,适配器终结者,">





  <link rel="alternate" href="/atom.xml" title="班德尔城" type="application/atom+xml">






<meta name="description" content="终结Adapter、ViewHolder，封装通用适配器">
<meta name="keywords" content="Android-Adapter,适配器终结者">
<meta property="og:type" content="article">
<meta property="og:title" content="Android适配器终结者？">
<meta property="og:url" content="https://tiimor.cn/Android适配器终结者？/index.html">
<meta property="og:site_name" content="班德尔城">
<meta property="og:description" content="终结Adapter、ViewHolder，封装通用适配器">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://cdn.tiimor.cn/images/%E5%94%AF%E7%BE%8E%E7%AF%87%EF%BC%8D%E7%94%A8%E4%BD%A0%E7%9A%84%E9%92%A5%E5%8C%99%EF%BC%8C%E6%89%93%E5%BC%80%E6%88%91%E7%9A%84%E5%BF%83%E6%89%89.jpg">
<meta property="og:image" content="https://github.com/VeiZhang/BaseToolsLibrary/raw/master/images/common_adapter.png?raw=true">
<meta property="og:image" content="https://github.com/VeiZhang/BaseToolsLibrary/raw/master/images/multi_adapter.png?raw=true">
<meta property="og:updated_time" content="2019-03-17T06:47:42.368Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android适配器终结者？">
<meta name="twitter:description" content="终结Adapter、ViewHolder，封装通用适配器">
<meta name="twitter:image" content="http://cdn.tiimor.cn/images/%E5%94%AF%E7%BE%8E%E7%AF%87%EF%BC%8D%E7%94%A8%E4%BD%A0%E7%9A%84%E9%92%A5%E5%8C%99%EF%BC%8C%E6%89%93%E5%BC%80%E6%88%91%E7%9A%84%E5%BF%83%E6%89%89.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '3AUIZWGETM',
      apiKey: '5fcd6d51d892fffe3480c5b37f5fd4fa',
      indexName: 'Tiimor',
      hits: {"per_page":8},
      labels: {"input_placeholder":"搜索","hits_empty":"未发现与「${query}」相关的内容","hits_stats":"${hits} 条相关条目，使用了 ${time} 毫秒"}
    }
  };
</script>



  <link rel="canonical" href="https://tiimor.cn/Android适配器终结者？/">





  <title>Android适配器终结者？ | 班德尔城</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-96457043-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?abb97f8f68c9e5eb2217d3111c64e696";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

  <!-- modify by zhangwei -->
  <!-- 下雪的动画 -->
  <div class="canvas-snow">
    <canvas id="canvas" style="margin: 0;  padding: 0;top:0; left: 0; right: 0; background: transparent; position: absolute;" width="1366" height="105"></canvas>
      <script>

      var canvasBgImg = {
        start: function () {
          this.canvas = document.getElementById('canvas')
          this.ctx = this.canvas.getContext("2d")
          this.canvas.width = window.innerWidth
          this.canvas.height = 105
          this.starList = []
        },
        drawLine: function (ctx, x1, y1, x2, y2) {
          ctx.beginPath()
          ctx.strokeStyle = '#ffffff'
          ctx.lineTo(x1, y1)
          ctx.lineTo(x2, y2)
          ctx.stroke()
        },
        canvasSingleSnow: function (snowSize) {
          var singleSnow = document.createElement('canvas'),
            ctxSingle = singleSnow.getContext('2d')
          singleSnow.setAttribute('width', snowSize * 2)
          singleSnow.setAttribute('height', snowSize * 2)
          for (var i = 0; i < 6; i++) {
            ctxSingle.save()
            ctxSingle.translate(snowSize, snowSize)
            ctxSingle.rotate(Math.PI * 2 * i / 6)
            this.drawLine(ctxSingle, 0, 0, snowSize, 0)
            ctxSingle.restore()
          }
          return singleSnow
        },
        canvasAllSnow: function (centerSnow) {
          var canvasSnow = document.createElement('canvas'),
            ctxSnow = canvasSnow.getContext('2d'),
            bigSnow = this.canvasSingleSnow(centerSnow),
            smallSnow = this.canvasSingleSnow(centerSnow / 3),
            sizeSnow = centerSnow * 3 / 5,
            rSnow = centerSnow - sizeSnow / 2
          canvasSnow.setAttribute('width', centerSnow * 2)
          canvasSnow.setAttribute('height', centerSnow * 2)
          ctxSnow.drawImage(bigSnow, 0, 0, bigSnow.width, bigSnow.height, 0, 0, centerSnow * 2, centerSnow * 2)
          for (var i = 0; i < 6; i++) {
            ctxSnow.save()
            ctxSnow.translate(centerSnow, centerSnow)
            ctxSnow.rotate(Math.PI * 2 * i / 6)
            ctxSnow.drawImage(smallSnow, 0, 0, smallSnow.width, smallSnow.height, rSnow - sizeSnow / 2,
              -sizeSnow / 2, sizeSnow, sizeSnow)
            ctxSnow.restore()
          }
          return canvasSnow
        },
        init: function () {
          this.start()
          for (var i = 0; i < 75; i++) {
            this.starList.push({
              drawFunc: this.canvasAllSnow(15),
              width: Math.random() * this.canvas.width,
              height: Math.random() * this.canvas.height,
              speed: Math.random() * 1.5 + .5,
              scale: Math.random() * 12 + 5,
              angel: 0
            })
          }
          var self = this,
            loop = function () {
              self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.width)
              for (var i = 0; i < 75; i++) {
                self.ctx.save()
                self.starList[i].height = self.starList[i].height + self.starList[i].speed
                self.starList[i].angel += 2
                self.ctx.translate(self.starList[i].width, self.starList[i].height)
                self.ctx.rotate(self.starList[i].angel * Math.PI / 360)
                self.ctx.translate(-self.starList[i].width, -self.starList[i].height)
                self.ctx.drawImage(self.starList[i].drawFunc, 0, 0,
                  self.starList[i].drawFunc.width, self.starList[i].drawFunc.height,
                  self.starList[i].width - self.starList[i].scale / 2,
                  self.starList[i].height - self.starList[i].scale / 2,
                  self.starList[i].scale, self.starList[i].scale)
                if (self.starList[i].height > self.canvas.height) {
                  self.starList[i] = Object.assign(self.starList[i], {
                    height: -self.starList[i].scale,
                    width: Math.random() * this.canvas.width
                  })
                }
                self.ctx.restore()
              }
              requestAnimationFrame(loop)
            }
          requestAnimationFrame(loop)
        }
      }
      canvasBgImg.init()
      </script>

    </div>


    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <!-- modify by zhangwei -->
        <!-- 圣诞帽 -->
        <img src="/uploads/santa-hat.png" id="santa" style="height: 41px; position: absolute; left: -40px; top: -20px; transform: rotate(-45deg); z-index: 9000;">

        <span class="logo-line-before"><i></i></span>
        <span class="site-title">班德尔城</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">微笑，简单，奋发</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-guestbook">
          <a href="/guestbook" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-send"></i> <br>
            
            留言
          </a>
        </li>
      
        
        <li class="menu-item menu-item-favourite">
          <a href="/favourite" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-bookmark"></i> <br>
            
            收藏
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tiimor.cn/Android适配器终结者？/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tiimor">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="班德尔城">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android适配器终结者？</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-22T14:39:56+08:00">
                2017-10-22
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android联盟/" itemprop="url" rel="index">
                    <span itemprop="name">Android联盟</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/Android适配器终结者？/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/Android适配器终结者？/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/Android适配器终结者？/" class="leancloud_visitors" data-flag-title="Android适配器终结者？">
               <span class="post-meta-divider">|</span>
               <!-- modify by zhangwei -->
               <!-- 去掉阅读的眼睛图标，阅读次数改为℃ -->
			   
                 <span class="post-meta-item-text">热度 </span>
               
                 <span class="leancloud-visitors-count"></span>
				 <span>℃</span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="http://cdn.tiimor.cn/images/%E5%94%AF%E7%BE%8E%E7%AF%87%EF%BC%8D%E7%94%A8%E4%BD%A0%E7%9A%84%E9%92%A5%E5%8C%99%EF%BC%8C%E6%89%93%E5%BC%80%E6%88%91%E7%9A%84%E5%BF%83%E6%89%89.jpg" alt="Android" title="&#x7528;&#x4F60;&#x7684;&#x94A5;&#x5319;&#xFF0C;&#x6253;&#x5F00;&#x6211;&#x7684;&#x5FC3;&#x6249;"></p>
<p><strong>&#x7EC8;&#x7ED3;Adapter&#x3001;ViewHolder&#xFF0C;&#x5C01;&#x88C5;&#x901A;&#x7528;&#x9002;&#x914D;&#x5668;</strong></p>
<a id="more"></a>
<font size="4"><strong><a href="https://github.com/VeiZhang/BaseToolsLibrary" target="_blank" rel="noopener">&#x9879;&#x76EE;&#x4F20;&#x9001;&#x95E8;</a></strong></font>

<figure class="highlight gradle"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">compile</span> <span class="string">&apos;com.excellence:basetools:1.2.4&apos;</span></span><br></pre></td></tr></tbody></table></figure>
<h1 id="Android&#x9002;&#x914D;&#x5668;"><a href="#Android&#x9002;&#x914D;&#x5668;" class="headerlink" title="Android&#x9002;&#x914D;&#x5668;"></a>Android&#x9002;&#x914D;&#x5668;</h1><p>&#x5728;Android&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x7ECF;&#x5E38;&#x4F7F;&#x7528;Adapter&#x548C;ViewHolder&#xFF0C;&#x603B;&#x662F;&#x5199;&#x7740;&#x5343;&#x7BC7;&#x4E00;&#x5F8B;&#x7684;&#x9002;&#x914D;&#x5668;&#x4EE3;&#x7801;&#xFF0C;&#x6240;&#x4EE5;&#x8FDB;&#x884C;&#x901A;&#x7528;&#x578B;&#x3001;&#x4E07;&#x80FD;&#x578B;&#x7684;Adapter&#x5C01;&#x88C5;&#x3002;</p>
<ul>
<li><p>MVVM&#x6A21;&#x5F0F;Adapter&#x5C01;&#x88C5;<br>&#x6700;&#x8FD1;&#x5B66;&#x4E60;MVVM&#xFF0C;&#x53D1;&#x73B0;&#x4E00;&#x7CFB;&#x5217;&#x4F18;&#x70B9;&#xFF0C;&#x9002;&#x914D;&#x5668;&#x5C01;&#x88C5;&#x4E5F;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x8BA9;ViewHolder&#x53BB;&#x6B7B;&#x5427;&#xFF0C;&#x53EA;&#x7559;&#x4E0B;&#x53EF;&#x7231;&#x7684;Adapter&#xFF1B;&#x5F00;&#x542F;DataBinding&#xFF0C;&#x8FDB;&#x884C;&#x5C01;&#x88C5;&#x3002;</p>
</li>
<li><p>&#x666E;&#x901A;Adapter&#x5C01;&#x88C5;<br>&#x5176;&#x4ED6;&#x73AF;&#x5883;&#x4E0B;&#xFF1A;&#x4E0D;&#x5F00;&#x542F;DataBinding&#xFF0C;&#x5C01;&#x88C5;Adapter&#x548C;ViewHolder&#xFF0C;&#x4F7F;&#x7528;&#x65F6;&#x9700;&#x8981;&#x5B9E;&#x73B0;Adapter&#x7684;&#x62BD;&#x8C61;&#x63A5;&#x53E3;&#x3002;</p>
</li>
</ul>
<p><strong>&#x4EE5;&#x4E0A;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x90FD;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;&#x3001;&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;&#x7684;&#x9002;&#x914D;&#x5668;&#x3002;</strong></p>
<h1 id="Adapter&#x793A;&#x4F8B;"><a href="#Adapter&#x793A;&#x4F8B;" class="headerlink" title="Adapter&#x793A;&#x4F8B;"></a>Adapter&#x793A;&#x4F8B;</h1><p><img src="https://github.com/VeiZhang/BaseToolsLibrary/raw/master/images/common_adapter.png?raw=true" alt="&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;" title="&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;"></p>
<p><img src="https://github.com/VeiZhang/BaseToolsLibrary/raw/master/images/multi_adapter.png?raw=true" alt="&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;" title="&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;"></p>
<h2 id="MVVM&#x6A21;&#x5F0F;Adapter&#x793A;&#x4F8B;"><a href="#MVVM&#x6A21;&#x5F0F;Adapter&#x793A;&#x4F8B;" class="headerlink" title="MVVM&#x6A21;&#x5F0F;Adapter&#x793A;&#x4F8B;"></a>MVVM&#x6A21;&#x5F0F;Adapter&#x793A;&#x4F8B;</h2><h3 id="DataBinding&#xFF0C;ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;"><a href="#DataBinding&#xFF0C;ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;" class="headerlink" title="DataBinding&#xFF0C;ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;"></a>DataBinding&#xFF0C;ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;</h3><ul>
<li><p>&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br><strong>&#x7B80;&#x5355;&#x5230;&#x7206;&#x70B8;&#x6709;&#x6728;&#x6709;!!!</strong></p>
<figure class="highlight jboss-cli"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">//</span> &#x76F4;&#x63A5;&#x521B;&#x5EFA;CommonBindingAdapter</span><br><span class="line">CommonBindingAdapter&lt;Flower&gt; adapter = new CommonBindingAdapter&lt;&gt;<span class="params">(mFlowers, R.layout.item_flower, BR.flower)</span>;</span><br><span class="line"><span class="string">//</span> &#x8BBE;&#x7F6E;&#x9002;&#x914D;&#x5668;&#xFF0C;&#x7B49;&#x540C;&#x4E8E;ListView.<span class="keyword">set</span>Adapter<span class="params">()</span>&#x3001;GridView.<span class="keyword">set</span>Adapter<span class="params">()</span></span><br><span class="line">mBinding.<span class="keyword">set</span>Adapter<span class="params">(adapter)</span>;</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br>&#x4E3B;&#x8981;&#x662F;&#x5B9E;&#x73B0;&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;&#x7684;<code>ViewDelegate</code>&#x7684;&#x63A5;&#x53E3;</p>
<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x76F4;&#x63A5;&#x521B;&#x5EFA;MultiItemTypeBindingAdapter</span></span><br><span class="line">MultiItemTypeBindingAdapter&lt;Flower&gt; adapter = <span class="keyword">new</span> <span class="type">MultiItemTypeBindingAdapter</span>&lt;&gt;(mFlowers);</span><br><span class="line"><span class="comment">// &#x6DFB;&#x52A0;&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;</span></span><br><span class="line">adapter.addItemViewDelegate(<span class="keyword">new</span> <span class="type">RoseViewDelegate</span>());</span><br><span class="line">adapter.addItemViewDelegate(<span class="keyword">new</span> <span class="type">TulipViewDelegate</span>());</span><br><span class="line"><span class="comment">// &#x8BBE;&#x7F6E;&#x9002;&#x914D;&#x5668;</span></span><br><span class="line">mBinding.setAdapter(adapter);</span><br></pre></td></tr></tbody></table></figure>
<p>  &#x5B9E;&#x73B0;<code>ItemViewDelegate</code>&#x7684;&#x63A5;&#x53E3;</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">RoseViewDelegate</span> <span class="keyword">implements</span> <span class="title">ItemViewDelegate</span>&lt;<span class="title">Flower</span>&gt;</span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getItemViewLayoutId</span><span class="params">()</span></span></span><br><span class="line"><span class="function">	</span>{</span><br><span class="line">		<span class="keyword">return</span> R.layout.item_rose;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getItemVariable</span><span class="params">()</span></span></span><br><span class="line"><span class="function">	</span>{</span><br><span class="line">		<span class="keyword">return</span> BR.rose;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isForViewType</span><span class="params">(Flower item, <span class="keyword">int</span> position)</span></span></span><br><span class="line"><span class="function">	</span>{</span><br><span class="line">		<span class="keyword">return</span> item <span class="keyword">instanceof</span> Rose;</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h3 id="DataBinding&#xFF0C;RecyclerView&#x9002;&#x914D;&#x5668;"><a href="#DataBinding&#xFF0C;RecyclerView&#x9002;&#x914D;&#x5668;" class="headerlink" title="DataBinding&#xFF0C;RecyclerView&#x9002;&#x914D;&#x5668;"></a>DataBinding&#xFF0C;RecyclerView&#x9002;&#x914D;&#x5668;</h3><p>&#x540C;&#x4E0A;</p>
<ul>
<li><p>&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;</p>
<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x76F4;&#x63A5;&#x521B;&#x5EFA;BaseRecyclerBindingAdapter</span></span><br><span class="line">BaseRecyclerBindingAdapter&lt;Flower&gt; adapter = <span class="keyword">new</span> <span class="type">BaseRecyclerBindingAdapter</span>&lt;&gt;(mFlowers, R.layout.item_flower, BR.flower);</span><br><span class="line"><span class="comment">// &#x8BBE;&#x7F6E;&#x9002;&#x914D;&#x5668;&#xFF0C;&#x7B49;&#x540C;&#x4E8E;RecyclerView.setAdapter()</span></span><br><span class="line">mBinding.setAdapter(adapter);</span><br><span class="line"><span class="comment">// &#x6CE8;&#x610F;&#x8BBE;&#x7F6E;LayoutManager&#xFF0C;&#x7B49;&#x540C;&#x4E8E;RecyclerView.setLayoutManager()</span></span><br><span class="line">mBinding.setLayoutManager(<span class="keyword">new</span> <span class="type">LinearLayoutManager</span>(<span class="built_in">this</span>));</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;</p>
<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">MultiItemTypeBindingRecyclerAdapter&lt;Flower&gt; adapter = <span class="keyword">new</span> <span class="type">MultiItemTypeBindingRecyclerAdapter</span>&lt;&gt;(mFlowers);</span><br><span class="line">adapter.addItemViewDelegate(<span class="keyword">new</span> <span class="type">RoseViewDelegate</span>());</span><br><span class="line">adapter.addItemViewDelegate(<span class="keyword">new</span> <span class="type">TulipViewDelegate</span>());</span><br><span class="line">mBinding.setAdapter(adapter);</span><br><span class="line">mBinding.setLayoutManager(<span class="keyword">new</span> <span class="type">LinearLayoutManager</span>(<span class="built_in">this</span>));</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h2 id="&#x666E;&#x901A;Adapter&#x793A;&#x4F8B;"><a href="#&#x666E;&#x901A;Adapter&#x793A;&#x4F8B;" class="headerlink" title="&#x666E;&#x901A;Adapter&#x793A;&#x4F8B;"></a>&#x666E;&#x901A;Adapter&#x793A;&#x4F8B;</h2><h3 id="ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;"><a href="#ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;" class="headerlink" title="ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;"></a>ListVew&#x3001;GridView&#x9002;&#x914D;&#x5668;</h3><ul>
<li><p>&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br>&#x5B9E;&#x73B0;<code>CommonAdapter</code>&#x7684;&#x63A5;&#x53E3;</p>
<figure class="highlight scala"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x521B;&#x5EFA;adapter&#x7C7B;&#x7EE7;&#x627F;CommonAdapter&#xFF0C;&#x7136;&#x540E;&#x8BBE;&#x7F6E;&#x9002;&#x914D;&#x5668;&#x5373;&#x53EF;</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">AppGridAdapter</span> <span class="keyword">extends</span> <span class="title">CommonAdapter&lt;ResolveInfo&gt;</span></span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    public <span class="type">AppGridAdapter</span>(<span class="type">Context</span> context, <span class="type">List</span>&lt;<span class="type">ResolveInfo</span>&gt; datas, int layoutId)</span><br><span class="line">    {</span><br><span class="line">        <span class="keyword">super</span>(context, datas, layoutId);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    public void convert(<span class="type">ViewHolder</span> viewHolder, <span class="type">ResolveInfo</span> item, int position)</span><br><span class="line">    {</span><br><span class="line">		<span class="comment">// ViewHolder&#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x4E9B;&#x8F85;&#x52A9;&#x65B9;&#x6CD5;&#xFF0C;&#x65B9;&#x4FBF;View&#x7684;&#x5404;&#x79CD;&#x8BBE;&#x7F6E;</span></span><br><span class="line">        <span class="type">ImageView</span> iconView = viewHolder.getView(android.<span class="type">R</span>.id.icon);</span><br><span class="line">        iconView.setImageDrawable(item.loadIcon(mPackageManager));</span><br><span class="line">        viewHolder.setText(android.<span class="type">R</span>.id.text1, item.loadLabel(mPackageManager).toString());</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br>&#x5B9E;&#x73B0;<code>ItemViewDelegate</code>&#x63A5;&#x53E3;</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x591A;&#x5E03;&#x5C40;&#x9002;&#x914D;&#x5668;</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">ChatAdapter</span> <span class="keyword">extends</span> <span class="title">MultiItemTypeAdapter</span>&lt;<span class="title">People</span>&gt;</span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">ChatAdapter</span><span class="params">(Context context, List&lt;People&gt; messages)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">super</span>(context, messages);</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> ComputerDelegate());</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> BlueDelegate());</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> PurpleDelegate());</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x4E0D;&#x540C;&#x7684;&#x5E03;&#x5C40;&#x89C6;&#x56FE;</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">ComputerDelegate</span> <span class="keyword">implements</span> <span class="title">ItemViewDelegate</span>&lt;<span class="title">People</span>&gt;</span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getItemViewLayoutId</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">return</span> R.layout.item_computer;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isForViewType</span><span class="params">(People item, <span class="keyword">int</span> position)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">return</span> item <span class="keyword">instanceof</span> ComputerData;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">convert</span><span class="params">(ViewHolder viewHolder, People item, <span class="keyword">int</span> position)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        viewHolder.setText(R.id.computer_text, item.getMsg());</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h3 id="RecyclerView&#x9002;&#x914D;&#x5668;"><a href="#RecyclerView&#x9002;&#x914D;&#x5668;" class="headerlink" title="RecyclerView&#x9002;&#x914D;&#x5668;"></a>RecyclerView&#x9002;&#x914D;&#x5668;</h3><ul>
<li><p>&#x5355;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br>&#x5B9E;&#x73B0;<code>BaseRecyclerAdapter</code>&#x7684;&#x63A5;&#x53E3;</p>
<figure class="highlight scala"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x521B;&#x5EFA;adapter&#x7C7B;&#x7EE7;&#x627F;BaseRecyclerAdapter</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">AppRecyclerAdapter</span> <span class="keyword">extends</span> <span class="title">BaseRecyclerAdapter&lt;ResolveInfo&gt;</span></span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    <span class="keyword">private</span> <span class="type">PackageManager</span> mPackageManager = <span class="literal">null</span>;</span><br><span class="line"></span><br><span class="line">    public <span class="type">AppRecyclerAdapter</span>(<span class="type">Context</span> context, <span class="type">List</span>&lt;<span class="type">ResolveInfo</span>&gt; datas, int layoutId)</span><br><span class="line">    {</span><br><span class="line">        <span class="keyword">super</span>(context, datas, layoutId);</span><br><span class="line">        mPackageManager = context.getPackageManager();</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    public void convert(<span class="type">RecyclerViewHolder</span> viewHolder, <span class="type">ResolveInfo</span> item, int position)</span><br><span class="line">    {</span><br><span class="line">		<span class="comment">// ViewHolder&#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x4E9B;&#x8F85;&#x52A9;&#x65B9;&#x6CD5;&#xFF0C;&#x65B9;&#x4FBF;View&#x7684;&#x5404;&#x79CD;&#x8BBE;&#x7F6E;</span></span><br><span class="line">        viewHolder.setText(android.<span class="type">R</span>.id.text1, item.loadLabel(mPackageManager));</span><br><span class="line">        viewHolder.setImageDrawable(android.<span class="type">R</span>.id.icon, item.loadIcon(mPackageManager));</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x591A;&#x5E03;&#x5C40;&#x7C7B;&#x578B;<br>&#x5B9E;&#x73B0;<code>ItemViewDelegate</code>&#x7684;&#x63A5;&#x53E3;</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x591A;&#x5E03;&#x5C40;&#x9002;&#x914D;&#x5668;</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">WarAdapter</span> <span class="keyword">extends</span> <span class="title">MultiItemTypeRecyclerAdapter</span>&lt;<span class="title">People</span>&gt;</span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">WarAdapter</span><span class="params">(Context context, List&lt;People&gt; datas)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">super</span>(context, datas);</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> ComputerRecyclerDelegate());</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> BlueRecyclerDelegate());</span><br><span class="line">        addItemViewDelegate(<span class="keyword">new</span> PurpleRecyclerDelegate());</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x4E0D;&#x540C;&#x7684;&#x5E03;&#x5C40;&#x89C6;&#x56FE;</span></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">class</span> <span class="title">ComputerRecyclerDelegate</span> <span class="keyword">implements</span> <span class="title">ItemViewDelegate</span>&lt;<span class="title">People</span>&gt;</span></span><br><span class="line"><span class="class"></span>{</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getItemViewLayoutId</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">return</span> R.layout.item_computer;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isForViewType</span><span class="params">(People item, <span class="keyword">int</span> position)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        <span class="keyword">return</span> item <span class="keyword">instanceof</span> ComputerData;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">convert</span><span class="params">(RecyclerViewHolder viewHolder, People item, <span class="keyword">int</span> position)</span></span></span><br><span class="line"><span class="function">    </span>{</span><br><span class="line">        viewHolder.setText(R.id.computer_text, item.getMsg());</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<font size="4"><strong>&#x6B22;&#x8FCE;star!!!</strong></font>

<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>谢谢老板，请尽情用红包来蹂躏我吧！！！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/uploads/wechatpay.jpg" alt="Tiimor 微信打赏">
        <p>微信打赏</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/uploads/alipay.jpg" alt="Tiimor 支付宝打赏">
        <p>支付宝打赏</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/Android-Adapter/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>Android-Adapter</a>
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/适配器终结者/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>适配器终结者</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/Android6-0-动态权限管理/" rel="next" title="Android6.0+动态权限管理">
                <i class="fa fa-chevron-left"></i> Android6.0+动态权限管理
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/Android白银篇-GreenDao3/" rel="prev" title="Android白银篇-GreenDao3">
                Android白银篇-GreenDao3 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="Tiimor">
            
              <p class="site-author-name" itemprop="name">Tiimor</p>
              <p class="site-description motion-element" itemprop="description">安静地做一只攻城狮。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/VeiZhang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.weibo.com/tiimor" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/589972d0570c3500624fd791" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-anchor"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.jianshu.com/u/93b886580243" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://wpa.qq.com/msgrd?v=3&uin=690393541&site=qq&menu=yes" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:tiimor@qq.com" target="_blank" title="邮箱">
                      
                        <i class="fa fa-fw fa-envelope"></i>邮箱</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Android适配器"><span class="nav-number">1.</span> <span class="nav-text">Android适配器</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Adapter示例"><span class="nav-number">2.</span> <span class="nav-text">Adapter示例</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#MVVM模式Adapter示例"><span class="nav-number">2.1.</span> <span class="nav-text">MVVM模式Adapter示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#DataBinding，ListVew、GridView适配器"><span class="nav-number">2.1.1.</span> <span class="nav-text">DataBinding，ListVew、GridView适配器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DataBinding，RecyclerView适配器"><span class="nav-number">2.1.2.</span> <span class="nav-text">DataBinding，RecyclerView适配器</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#普通Adapter示例"><span class="nav-number">2.2.</span> <span class="nav-text">普通Adapter示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ListVew、GridView适配器"><span class="nav-number">2.2.1.</span> <span class="nav-text">ListVew、GridView适配器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RecyclerView适配器"><span class="nav-number">2.2.2.</span> <span class="nav-text">RecyclerView适配器</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tiimor</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a></div>




        
<div class="busuanzi-count">
  <!-- modify by zhangwei -->
  <!-- 修改不蒜子统计脚本 -->
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>



<script>
  	var _mtac = {};
  	(function() {
  		var mta = document.createElement("script");
  		mta.src = "https://pingjs.qq.com/h5/stats.js?v2.0.4";
  		mta.setAttribute("name", "MTAH5");
  		mta.setAttribute("sid", "500425805");

  		var s = document.getElementsByTagName("script")[0];
  		s.parentNode.insertBefore(mta, s);
  	})();
</script>


  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=61441764";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            <!-- modify by zhangwei -->
            <!-- 修复gitment评论页初始化错误@tiimor -->
            id: '1508654396000', 
            owner: 'VeiZhang',
            repo: 'veizhang.github.io',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: '9919bc61413a89ea3eb156910d282e3103093e32',
            
                client_id: 'f08924ca58e61d6f51f4'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    







  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("7aBs9I9Y3PjoN6ueX5J3AYQW-gzGzoHsz", "kboycyzaPNAYcUW8AkF3edeW");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

  
  <!-- modify by zhangwei -->
  <!-- 动态时间小人 -->
  <!-- modify by zhangwei -->
<!-- 动态时间小人 -->
<!-- z-index -1 表示在最底层，不能悬浮也不能点击 -->
<!-- z-index auto 可以点击 -->
<!-- z-index 9999 无限大时，总是在最上层，会影响其他悬浮框 -->
<div id="dg" style="z-index: auto; position: fixed ! important; right: 0px; top: 0px;">  
    <table width 100% style="position: absolute; width:260px; right: 0px; top: 0px;">  
		<div>
			<embed wmode="transparent" src="http://cdn.tiimor.cn/images/dynamic_time.swf" quality="high" bgcolor="#ffffff" width="160" height="70" name="honehoneclock" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
		</div>
    </table>  
</div>
  
</body>
</html>
